

use transaction_all_id_conc$firstyear$lastyear, clear
id_group id_bp "iso2 buyer id_conc"
bys id_bp iso2: egen count_transaction=count(export)
collapse (mean) count_transaction (sum) export, by(id_bp iso2)
collapse (count) count_bp=export (sum) export, by(count_transaction)

gsort count_transaction
g cumulated_count_bp=sum(count_bp)
egen _=sum(count_bp)
replace cumulated_count_bp=cumulated_count_bp/_
drop _

gsort count_transaction
g cumulated_export=sum(export)
egen _=sum(export)
replace cumulated_export=cumulated_export/_
drop _

scatter cumulated_count_bp cumulated_export count_transaction if count_transaction<200, xscale(log) scheme(s1mono) xlabel(1 2 5 10 50 200) xtitle("Count transactions per bp") ytitle(" ") legend(lab(1 "Share of buyer*products") lab(2 "Value share"))
gr export "$outputpath/figure_online_2.pdf", replace